package com.hdf.etdemo.viewframe;

import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.etdemo.R;
import com.hdf.etdemo.R.id;
import com.hdf.etdemo.R.layout;
import com.hdf.etdemo.viewframe.fragment.HomeF1;
import com.hdf.etdemo.viewframe.fragment.HomeF2;
import com.hdf.etdemo.viewframe.fragment.HomeF3;
import com.hdf.etdemo.viewframe.fragment.HomeF4;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.RadioButton;
import android.widget.RadioGroup;


public class HomeFragmentActivity extends EasyToolsActivity {
	private HomeF1 home1;
	private HomeF2 home2;
	private HomeF3 home3;
	private HomeF4 home4;
	private RadioGroup mRadioGroup;
	private RadioButton radio1,radio2,radio3,radio4;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home_fragment);
		setActionBarVib();
		initView();
	}
	private void initView()
	{
		mRadioGroup=(RadioGroup) findViewById(R.id.menu_group);
		radio1=(RadioButton) findViewById(R.id.radio_home);
		radio2=(RadioButton) findViewById(R.id.radio_account);
		radio3=(RadioButton) findViewById(R.id.radio_money);
		radio4=(RadioButton) findViewById(R.id.radio_more);
		handleAction();
		showFragment(1);
	}
	private void handleAction() {
		mRadioGroup
				.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
					@Override
					public void onCheckedChanged(RadioGroup radioGroup, int i) {
						switchTab(i);
					}
				});
	}

	protected void switchTab(int id) {
		switch (id) {
		case R.id.radio_home:
			showFragment(1);
			break;
		case R.id.radio_account:
			showFragment(2);
			break;
		case R.id.radio_money:
			showFragment(3);
			break;
		case R.id.radio_more:
			showFragment(4);
			break;
		}
	}

	
	

	
	
	private void showFragment(int index) {
		FragmentManager fragmentManager = getFragmentManager();
		FragmentTransaction ft = fragmentManager.beginTransaction();
			// ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_left);
		hideFragment(ft);
		switch (index) {
		case 1:
			if (home1 != null)
				ft.show(home1);
			else {
				home1 = new HomeF1();
				ft.add(R.id.frame, home1);
			}
			break;
		case 2:
			if (home2 != null){
				ft.show(home2);
			}
			else {
				home2 = new HomeF2();
				ft.add(R.id.frame, home2);
			}
			break;
		case 3:
			if (home3 != null){
				ft.show(home3);
			}
			else {
				home3 = new HomeF3();
				ft.add(R.id.frame, home3);
			}
			break;
		case 4:
			if (home4 != null){
				ft.show(home4);
			}
			else {
				home4 = new HomeF4();
				ft.add(R.id.frame, home4);
			}
			break;
		}
		ft.commitAllowingStateLoss();
	}
		private void hideFragment(FragmentTransaction ft) {
			if (home1 != null)
				ft.hide(home1);
			if (home2 != null)
				ft.hide(home2);
			if (home3 != null)
				ft.hide(home3);
			if (home4 != null)
				ft.hide(home4);
		}
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			
		}
	
}
